﻿//interface IShape
//{
//    double GetArea();
//    bool IsLegal();
//}
public enum EShape {
    Rectangle,
    Square,
    Triangle,
}

public abstract class Shape {
    public abstract double GetArea();
    public abstract bool IsLegal();
}

public class Rectangle : Shape {
    readonly int width;
    readonly int height;
    public Rectangle(int width, int height) {
        this.width = width;
        this.height = height;
    }
    public override double GetArea() {
        if (!IsLegal()) {
            throw new ArgumentException("ShapeData illegal");
        }

        return width * height;
    }
    public override bool IsLegal() => width > 0 && height > 0;
}

public class Square : Rectangle {
    public Square(int width) : base(width, width) { }
}

public class Triangle : Shape {
    readonly int a, b, c;
    public Triangle(int a, int b, int c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public override double GetArea() {
        if (!IsLegal()) {
            throw new ArgumentException("ShapeData illegal.");
        }
        //海伦公式
        var p = (double)(a + b + c) / 2;
        return Math.Sqrt(p * (p - a) * (p - b) * (p - c));
    }

    public override bool IsLegal() => (a + b > c) && (a + c > b) && (b + c > a);
    static void Main() {

    }
}